﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using FacePassword.UI;
using FacePassword.Business_Layer;
using FacePassword.Face_Recognition;

namespace FacePassword
{
    
    public partial class TrainUser : Form
    { 
        WeberFR wF = new WeberFR();

        Train_Features_Manager tFm = new Train_Features_Manager();

        DetectFaceForm faceFormDetect = null;

        public int counter;

        private bool rightBoxClicked = false;

        private bool leftBoxClicked = false;

        private bool upBoxClicked = false;

        private bool frontBoxClicked = false;

        private bool downBoxClicked = false;
            
        public TrainUser()
        {
          
            InitializeComponent();
            
        }

        private void trainbtn_Click(object sender, EventArgs e)
        {
            faceFormDetect = new DetectFaceForm();

            counter++;
            
            faceFormDetect.ShowDialog();

            switch (counter)
            {
                
                case 2:
                    {
                        leftHighlite.BackColor = Color.Red;
                       
                        rightHighlite.BackColor = Color.Gray;
                        
                        UpHighlite.BackColor = Color.Gray;
                        
                        downHighlite.BackColor = Color.Gray;
                        
                        frontHighlite.BackColor = Color.Gray;

                        pictureBox1.Image = faceFormDetect.PutFrameToImgBoxToOtherForm();

                        break;
                    }
                case 3:
                    {
                        leftHighlite.BackColor = Color.Gray;
                        
                        rightHighlite.BackColor = Color.Gray;
                        
                        UpHighlite.BackColor = Color.Red;
                        
                        downHighlite.BackColor = Color.Gray;
                        
                        frontHighlite.BackColor = Color.Gray;

                        pictureBox2.Image = faceFormDetect.PutFrameToImgBoxToOtherForm();
                        
                        break;
                    }
                case 4:
                    {
                        leftHighlite.BackColor = Color.Gray;
                        
                        rightHighlite.BackColor = Color.Gray;
                        
                        UpHighlite.BackColor = Color.Gray;
                        
                        downHighlite.BackColor = Color.Red;
                        
                        frontHighlite.BackColor = Color.Gray;

                        pictureBox3.Image = faceFormDetect.PutFrameToImgBoxToOtherForm();
                        
                        break;
                    }
                case 5:
                    {
                        leftHighlite.BackColor = Color.Gray;
                        
                        rightHighlite.BackColor = Color.Gray;
                        
                        UpHighlite.BackColor = Color.Gray;
                        
                        downHighlite.BackColor = Color.Gray;
                        
                        frontHighlite.BackColor = Color.Red;

                        pictureBox4.Image = faceFormDetect.PutFrameToImgBoxToOtherForm();

                        break;
                    }


            }
            if (counter == 6)
            {
                pictureBox5.Image = faceFormDetect.PutFrameToImgBoxToOtherForm();
               
            }

            if (rightBoxClicked)
            {
                pictureBox1.Image = faceFormDetect.PutFrameToImgBoxToOtherForm();
            }

            else if (leftBoxClicked)
            {
                pictureBox2.Image = faceFormDetect.PutFrameToImgBoxToOtherForm();
            }

            else if (upBoxClicked)
            {
                pictureBox3.Image = faceFormDetect.PutFrameToImgBoxToOtherForm();
            }

            else if (downBoxClicked)
            {
                pictureBox4.Image = faceFormDetect.PutFrameToImgBoxToOtherForm();
            }

            else if (frontBoxClicked)
            {
                pictureBox5.Image = faceFormDetect.PutFrameToImgBoxToOtherForm();
            }

          
         }


        private void button2_Click(object sender, EventArgs e)
        {
            this.Close(); 
        }

        private void TrainUser_Load(object sender, EventArgs e)
        {
            
            leftHighlite.BackColor = Color.Gray;
           
            rightHighlite.BackColor = Color.Red;
            
            UpHighlite.BackColor = Color.Gray;
            
            downHighlite.BackColor = Color.Gray;
            
            frontHighlite.BackColor = Color.Gray;
            
            counter = 1;

        }

        private void Train_btn_Click(object sender, EventArgs e)
        {

         /*  double [] rightFace =  wF.FeatureExtraction(pictureBox1.Image);

           tFm.AddFeatureVectorToDB(rightFace, UID);

           double[] lefttFace = wF.FeatureExtraction(pictureBox2.Image);

           tFm.AddFeatureVectorToDB(rightFace, UID);

           double[] upFace = wF.FeatureExtraction(pictureBox3.Image);

           tFm.AddFeatureVectorToDB(rightFace, UID);

           double[] downFace = wF.FeatureExtraction(pictureBox4.Image);

           tFm.AddFeatureVectorToDB(rightFace, UID);

           double[] frontFace = wF.FeatureExtraction(pictureBox5.Image);

           tFm.AddFeatureVectorToDB(rightFace, UID);
            */
        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {

            leftHighlite.BackColor = Color.Gray;

            rightHighlite.BackColor = Color.Red;

            UpHighlite.BackColor = Color.Gray;

            downHighlite.BackColor = Color.Gray;

            frontHighlite.BackColor = Color.Gray;

            rightBoxClicked = true;

            leftBoxClicked = false;

            upBoxClicked = false;

            downBoxClicked = false;

            frontBoxClicked = false;

        }

        private void pictureBox2_Click(object sender, EventArgs e)
        {
            leftHighlite.BackColor = Color.Red;

            rightHighlite.BackColor = Color.Gray;

            UpHighlite.BackColor = Color.Gray;

            downHighlite.BackColor = Color.Gray;

            frontHighlite.BackColor = Color.Gray;

            rightBoxClicked = false;

            leftBoxClicked = true;

            upBoxClicked = false;

            downBoxClicked = false;

            frontBoxClicked = false;

        }

        private void pictureBox3_Click(object sender, EventArgs e)
        {
            leftHighlite.BackColor = Color.Gray;

            rightHighlite.BackColor = Color.Gray;

            UpHighlite.BackColor = Color.Red;

            downHighlite.BackColor = Color.Gray;

            frontHighlite.BackColor = Color.Gray;

            rightBoxClicked = false;

            leftBoxClicked = false;

            upBoxClicked = true;

            downBoxClicked = false;

            frontBoxClicked = false;

        }

        private void pictureBox4_Click(object sender, EventArgs e)
        {
            leftHighlite.BackColor = Color.Gray;

            rightHighlite.BackColor = Color.Gray;

            UpHighlite.BackColor = Color.Gray;

            downHighlite.BackColor = Color.Red;

            frontHighlite.BackColor = Color.Gray;

            rightBoxClicked = false;

            leftBoxClicked = false;

            upBoxClicked = false;

            downBoxClicked = true;

            frontBoxClicked = false;

        }

        private void pictureBox5_Click(object sender, EventArgs e)
        {
            leftHighlite.BackColor = Color.Gray;

            rightHighlite.BackColor = Color.Gray;

            UpHighlite.BackColor = Color.Gray;

            downHighlite.BackColor = Color.Gray;

            frontHighlite.BackColor = Color.Red;

            rightBoxClicked = false;

            leftBoxClicked = false;

            upBoxClicked = false;

            downBoxClicked = false;

            frontBoxClicked = true;

        }

       

        

        
    }
}
